package parser.nodes;

import java.util.ArrayList;
import java.util.List;
import parser.TokenOr;
import scanner.Token;

// Selector = {'.' ident | '[' Expression ']'}
public class SelectorNode extends Node {
    private List<TokenOr<ExpressionNode>> selectorList = new ArrayList<>();
    
    public void addSelector(Token identifier) {
        selectorList.add(new TokenOr<ExpressionNode>(identifier));
    }

    public List<TokenOr<ExpressionNode>> getSelectorList() {
        return selectorList;
    }
    
    public void addSelector(ExpressionNode expression) {
        selectorList.add(new TokenOr<>(expression));
    }
    
    @Override
    public void print() {
        indent();
        p("Selector:");
        for(TokenOr<ExpressionNode> selector : selectorList)
            selector.print();
        unindent();
    }

    @Override
    public void abstractPrint() {
        for(TokenOr<ExpressionNode> selector : selectorList) {
            if (selector.Node() != null) {
                p("[]");
                indent();
                selector.Node().abstractPrint();
                unindent();
            } else {
                p(".");
                indent();
                p(selector.Token());
                unindent();
            }
        }
    }
}
